package com.yan.activity;

import java.net.URL;
import java.util.ArrayList;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.widget.ListView;
import android.widget.ProgressBar;

public class paper extends Activity {
   
    //RSS Feed URL
    private final String CGR_FEED_URL = "http://gdata.youtube.com/feeds/videos?author=JimmyRcom&orderby=updated&alt=rss&racy=include";
   
    //XML Widgets
    private ListView listview_episodes;
    private ProgressBar progress_bar;
   
    //Arrays of Episode Data
    public static ArrayList<String> episode_titles;
    private ArrayList<String> episode_dates;
    private ArrayList<URL> episode_link;
    private ArrayList<String> episode_image;
    WebView mwebview;               
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      //  setContentView(R.layout.newyorktimes);
        downloadEpisodes(CGR_FEED_URL);
        
    }
    
    private void downloadEpisodes(String Url) {
        //Make Progress Bar Visible While Downloading Feed
        progress_bar.setVisibility(ProgressBar.VISIBLE);
        Log.d("CGRParser", "Downloading Feed");
        //Start an ASync Thread to take care of Downloading Feed
        new DownloadEpisodes().execute(Url);
    }
    
    public class DownloadEpisodes extends AsyncTask<String, Integer, ArrayList<Implement>> {
       
        @Override
        protected ArrayList<Implement> doInBackground(String... url) {
           
            //Download and Parse Feed
            XmlFeedParser parser = new XmlFeedParser();
            ArrayList<Implement> episodes = new ArrayList<Implement>();
            episodes = parser.parse(url[0]);
           
            return episodes;
        }
       
        @Override
        protected void onPostExecute(ArrayList<Implement> result) {
               
            //Feed has been Downloaded and Parsed, Display Data to User
            Log.d("CGRParser", "Feed Download Complete");
           // displayEpisodes(result);
           
        }

    }
  /*  
    private void displayEpisodes(ArrayList<Implement> episodes) {
       
        //Create String Arrays to seperate titles and dates
        Log.d("CGRParser", "Displaying Episode Titles To User");
        ArrayList<String> episode_titles = new ArrayList<String>();
        ArrayList<String> episode_dates = new ArrayList<String>();
        ArrayList<URL> episode_link = new ArrayList<URL>();
        ArrayList<String>episode_image=new ArrayList<String>();
        for (Implement episode : episodes) {
            Log.d("CGRParser", "Episode Title: " + episode.getTitle());
            episode_titles.add(episode.getTitle());
            episode_dates.add(episode.getDate());
            episode_link.add(episode.getLink());
            episode_image.add(episode.getImage());
            //System.out.println("size of episode_image" + episode.getImage());

        }
       
        this.episode_titles = episode_titles;
        this.episode_dates = episode_dates;
        this.episode_link= episode_link;
        this.episode_image=episode_image;
       
         if(episode_image.size() >0)  
         { 
             String mStrings[] = new String[episode_image.size()];
             
             mStrings = episode_image.toArray(mStrings);
             adapter=new ImageAdapter(this, mStrings,episode_titles);
             listview_episodes.setAdapter(adapter);
for(int i=0;i<episode_image.size();i++) 
             Log.d("Value of mString", mStrings[i].toString());  
         }  
         
        // System.out.println("mstring"+mStrings[0].toString());
       
        Log.d("Value of Episode_image", episode_image.toString());
        Log.d("Value of Episode title", episode_titles.toString());
        //Create a ListAdapter to Display the Titles in the ListView
        ListAdapter adapter = new ArrayAdapter<String>(Technical.this, R.layout.episode_row, R.id.title, episode_titles);
        listview_episodes.setAdapter(adapter);
       
        //Set Progress Bar Invisible since we are done with it
        progress_bar.setVisibility(ProgressBar.INVISIBLE);
       
    }

    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
       
        //Display the Title and Date to the user when they click on an episode
        Toast.makeText(this, episode_titles.get(position) + ": " + episode_dates.get(position)+":"
                +episode_link.get(position)+":"+episode_image.get(position), Toast.LENGTH_LONG).show();
        mwebview.loadUrl(episode_link.get(position).toString());
        //mwebview.setVisibility(View.VISIBLE);
        //setContentView(R.layout.webview);
    }
   
   
     */
     
   
}